### 9.2
# Criar uma funo que retorne grficos de anlise exploratria para duas variveis
# Dica deles, baixar pacote
install.packages("plotrix")
library("plotrix")
# e ver funo multhist
help(multhist)

# Fazendo aos pouquinhos

exp.2v <- function(x,y) 
{
    if(length(x)/length(y)==1)
    {
    par(mfrow= c(2,2))
    plot(y~x, main="Plot")
    boxplot(x,y, main="Bloxplot", names=c("x","y"), col=c("chartreuse4","darkblue"))
    multhist(list(x,y), col=c("chartreuse4","darkblue"),xlab="Valores",ylab="Frequncia",            main="Histograma")
    qqnorm(x, col="chartreuse4", xlab="Quantis tericos", ylab="Quantis observados", 
           main="Q-Q plot")
    par(new=T)
    qqnorm(y, col="darkblue", xlab="Quantis tericos", ylab="Quantis observados", 
           main="Q-Q plot", yaxt="n")
    qqline(x, col="chartreuse4")
    par(new=T)
    qqline(y, col="darkblue")
    par(mfrow= c(1,1))
    summary(x) 
    summary(y) 
    correlacao <- cor(x,y) 
    resultado <- list(summary(x), summary(y), correlacao)
    return(resultado)
    } 
   
    else(length(x)/length(y)<=1 | length(x)/length(y)>=1)
    {
    stop("vetores devem conter o mesmo numero de observacoes")
    }
    
}


## Inventando x e y para testar
x1 <- seq(1,50, by=1)
y1 <- seq(1,100, by=2)
y2 <- seq(1,50, by=2)

exp.2v(x1,y1) #deve rodar
exp.2v(x1,y2) #deve dar erro

